package com.qiang.consumer.controller;

import com.alibaba.fastjson.JSON;
import com.qiang.consumer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping(value = "product")
public class ProductController {

    @Autowired
    @Qualifier(value = "restTemplate")
    private RestTemplate restTemplate;

    @GetMapping("getUser")
    public String getUser() {
        UserDto body = this.restTemplate.getForEntity("http://USERSERVICE/user/{id}", UserDto.class, 1).getBody();
        System.out.println(JSON.toJSONString(body));
        return "success";
    }

    @Autowired
    private UserService userService;

    @GetMapping("getAllUser")
    public List<UserDto> findAllUser() {
        return userService.findAll();
    }



}
